﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model.EntityModel;
using DataAccess;
using System.Drawing.Printing;
using System.Drawing;
using System.Collections.ObjectModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for ViewRequestingMedicalContent.xaml
    /// </summary>
    public partial class ViewRequestingMedicalContent : UserControl
    {
        Complaint c = new Complaint();
        Model.EntityModel.RequestingMedical r = new Model.EntityModel.RequestingMedical();
        Actor ActorVictim = new Actor();
        Person victim = new Person();

        public ViewRequestingMedicalContent(long IdComplaint)
        {
            InitializeComponent();            
            UIWindowManager.SetWindowTitle(this, "Brigada De Protección a la Familia - Ver Solicitud Evaluacion Medica");
            try
            {               
                c.Id = IdComplaint;
                lblCaseNumber.Content = c.Id;
                r = RequestingMedicalDataAccess.GetRequestByIdComplaint(IdComplaint);
                ActorVictim = PersonAndActorDataAccess.GetActorByTypeAndComplaintId("Victima", IdComplaint);
                victim = PersonAndActorDataAccess.GetPersonById(ActorVictim.IdPerson);
                LblVictimName.Content = victim.Name+" "+victim.PaternalName+" "+victim.MaternalName;
                LblMedicalName.Content = r.MedicalName+" "+r.MedicalPaternalName+" "+r.MedicalMaternalName;
                LblMedicalCenter.Content = r.MedicalCenter;
                lblCaseDate.Content = r.RegistrationDate;
            }
            catch
            {
                MessageBox.Show("No hay una solicitud medica registrada para la denuncia", "Informacion",MessageBoxButton.OK,MessageBoxImage.Information);
                this.Loaded += KillApp;
            }            
        }

        private void KillApp(object sender, RoutedEventArgs e)
        {
            UIWindowManager.CleanWindow(this);
        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            DrpDownPrintOptions.IsOpen = true;
        }

        private void Print_Click(object sender, RoutedEventArgs e)
        {
            var items = new ObservableCollection<UserControl>();
            items.Add(new PrintRequestingMedical(c.Id));
            var a = new PrintPreviewDialogV2(items);
            a.MenuItem_Click(null, null);
        }

        private void PrintPreview_Click(object sender, RoutedEventArgs e)
        {
            var items = new ObservableCollection<UserControl>();
            items.Add(new PrintRequestingMedical(c.Id));
            var a = new PrintPreviewDialogV2(items);
            a.ShowDialog();            
        }   
    }
}
